﻿@model CourseModel
<vc:admin-widget widget-zone="course_details_subject_top" additional-data="Model"/>
@if (!string.IsNullOrEmpty(Model.Id))
{
    <div class="panel panel-default">
        <div class="panel-body">
            <div id="subjects-grid"></div>
        </div>
    </div>

    <script>
    $(document).ready(function() {
        $("#subjects-grid").kendoGrid({
            dataSource: {
                transport: {
                    read: {
                        url: "@Html.Raw(Url.Action("Subjects", "Course", new { courseId = Model.Id, area = Constants.AreaAdmin }))",
                        type: "POST",
                        dataType: "json",
                        data: addAntiForgeryToken
                    },
                    create: {
                        url: "@Html.Raw(Url.Action("SubjectAdd", "Course", new { courseId = Model.Id, area = Constants.AreaAdmin }))",
                        type: "POST",
                        dataType: "json",
                        data: addAntiForgeryToken
                    },
                    update: {
                        url: "@Html.Raw(Url.Action("SubjectUpdate", "Course", new { courseId = Model.Id, area = Constants.AreaAdmin }))",
                        type: "POST",
                        dataType: "json",
                        data: addAntiForgeryToken
                    },
                    destroy: {
                        url: "@Html.Raw(Url.Action("SubjectDelete", "Course", new { courseId = Model.Id, area = Constants.AreaAdmin }))",
                        type: "POST",
                        dataType: "json",
                        data: addAntiForgeryToken
                    },
                },
                schema: {
                    data: "Data",
                    total: "Total",
                    errors: "Errors",
                    model: {
                        id: "Id",
                        fields: {
                            Name: { editable: true, type: "string" },
                            DisplayOrder: { editable: true, type: "number" },
                            Id: { editable: false, type: "string" }
                        }
                    }
                },
                requestEnd: function (e) {
                    if (e.type == "create" || e.type == "update") {
                        this.read();
                    }
                },
                error: function(e) {
                    display_kendoui_grid_error(e);
                    // Cancel the changes
                    this.cancelChanges();
                },
                serverPaging: true,
                serverFiltering: true,
                serverSorting: true
            },
            pageable: {
                refresh: true,
                numeric: false,
                previousNext: false,
                info: false
            },
            toolbar: [{ name: "create", text: "@Loc["Admin.Common.AddNewRecord"]" }],
            editable: {
                confirmation: false,
                mode: "inline"
            },
            scrollable: false,
            columns: [
            {
                field: "Name",
                title: "@Loc["Admin.Courses.Course.Subject.Fields.Name"]",
                width: 400
            }, {
                field: "DisplayOrder",
                title: "@Loc["Admin.Courses.Course.Subject.Fields.DisplayOrder"]",
                //integer format
                format: "{0:0}",
                width: 100
            }, {
                command: [
                {
                    name: "edit",
                    text: {
                        edit: "@Loc["Admin.Common.Edit"]",
                        update: "@Loc["Admin.Common.Update"]",
                        cancel: "@Loc["Admin.Common.Cancel"]"
                    }
                }, {
                    name: "destroy",
                    text: "@Loc["Admin.Common.Delete"]"
                        }
                    ],
                    width: 200
                }
            ]
        });
    });
    </script>
}
else
{
    <div class="note note-info">
        @Loc["Admin.Courses.Course.Subject.SaveBeforeEdit"]
    </div>
}
<vc:admin-widget widget-zone="course_details_subject_bottom" additional-data="Model"/>